<template>
  <div class="pc-tradedetail inner-box">
    <bread :backTitle="$t('trade.title')" backRouter="/tradelist" :secTitle="$t('txDetail.title')"></bread>

    <h1>{{$t('txDetail.title')}}</h1>
    <div class="not-found table-shadow" v-if="txNotFound">
      <p>
        {{$t('components.noMsg')}}，
        <span
          @click="txNotFound=false;getTradeDetail(hash)"
        >{{$t('components.repeat')}}</span>
      </p>
    </div>
    <!-- 表格部分 -->
    <div class="data-table table-shadow" v-else>
      <div class="head">
        <span>{{$t('blockDetail.general')}}</span>
      </div>
      <div class="item line flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('home.txHash')}}</span>
        </label>
        <div class="item-text">
          <span>{{hash}}</span>
          <div
            class="copy-btn"
            v-clipboard:copy="hash"
            v-clipboard:success="success"
            v-clipboard:error="error"
          >{{$t('components.copy')}}</div>
        </div>
      </div>
      <div class="item flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.status')}}</span>
        </label>
        <div class="item-text">
          <span :class="['status',trade.state===1?'success':'faild']">
            <i class="iconfont" :class="trade.state===1?'iconchenggong':'iconcuowu'"></i>
            {{trade.txt}}
          </span>
        </div>
      </div>
      <div class="item line flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('blockDetail.title')}}</span>
        </label>
        <div class="item-text">
          <router-link :to="`/blockDetail?height=${trade.height}`" class="light">{{trade.height}}</router-link>
        </div>
      </div>
      <div class="item flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('trade.time')}} (UTC+8)</span>
        </label>
        <div class="item-text">{{trade.blockTime|caculateTime}}</div>
      </div>
      <div class="item line flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('trade.sender')}}</span>
        </label>
        <div class="item-text">
          <router-link :to="`/address?address=${trade.fromAddr}`" class="light">{{trade.fromAddr}}</router-link>
        </div>
      </div>
      <div class="item flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('trade.receiver')}}</span>
        </label>
        <div class="item-text">
          <router-link :to="`/address?address=${trade.tx.to}`" class="light">{{trade.tx.to}}</router-link>
        </div>
      </div>
      <div class="item line flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.value')}}</span>
        </label>
        <div class="item-text">{{trade|TradeValue}}</div>
      </div>
      <div class="item flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('trade.fee')}}</span>
        </label>
        <div class="item-text">{{trade.tx.fee|filterFee}}</div>
      </div>
      <div class="item line flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.random')}}</span>
        </label>
        <div class="item-text">{{String(trade.tx.nonce)}}</div>
      </div>
      <div class="item flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.execer')}}</span>
        </label>
        <div class="item-text">{{trade.tx.execer}}</div>
      </div>
      <div class="item line flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('trade.func')}}</span>
        </label>
        <div class="item-text">{{trade.actionName==='unknown'? 'none':trade.actionName}}</div>
      </div>
      <div class="item flex-left">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.txType')}}</span>
        </label>
        <div class="item-text">{{trade|tradeGroup}}</div>
      </div>
      <div class="markdown-data" v-if="trade.tx.execer==='user.write'">
        <markdown :content="markdownTxt"></markdown>
      </div>
      <div class="area line" v-if="trade.tx.execer!=='user.write'">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.inData')}}</span>
        </label>
        <div class="item-text">
          <pre class="preTxt" contenteditable="true"> 
            <code>{{trade.tx|decodeTransferNote}}</code>
          </pre>
        </div>
      </div>
      <div class="area line" v-if="trade.tx.execer!=='user.write'">
        <label>
          <!-- <i class="iconfont iconwenhao"></i> -->
          <span>{{$t('txDetail.outData')}}</span>
        </label>
        <div class="item-text">
          <pre class="preTxt" contenteditable="true">
            <code>{{trade.receipt}}</code>
          </pre>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Bread from "@/components/computer/Breadcrumb.vue";
import tradeDetail from "@/mixins/TradeDetail/tradedetail.js";
export default {
  components: {
    markdown: () => import("@/components/markdown"),
    Bread
  },
  mixins: [tradeDetail]
};
</script>

<style lang="scss" scoped>
.pc-tradedetail {
  h1 {
    margin: 36px 0 16px;
    font-size: 16px;
    font-family: PingFangSC-Semibold;
    font-weight: 500;
    color: $black_title;
  }
  .not-found {
    width: 100%;
    background: $white;
    text-align: center;
    color: $black;
    p {
      font-size: 14px;
      line-height: 52px;
      margin: 15px 0;
    }
    span {
      color: #366c96;
      cursor: pointer;
    }
  }
  .data-table {
    width: 100%;
    color: $black;
    font-size: 14px;
    background: $white;
    border-radius: 2px;
    border: 1px solid rgba(235, 239, 241, 1);
    .head {
      height: 70px;
      border-bottom: 1px solid #eee;
      span {
        display: inline-block;
        height: 100%;
        width: 40px;
        margin-left: 32px;
        line-height: 67px;
        color: $black;
        font-size: 16px;
        font-family: PingFangSC-Semibold;
        font-weight: 500;
        text-align: center;
        border-bottom: 3px solid $blue;
      }
    }
    .item {
      height: 60px;
      label {
        width: 233px;
        display: flex;
        justify-items: left;
        align-items: center;
        padding-left: 32px;
        i {
          font-size: 20px;
          color: #b5d2e9;
        }
        span {
          margin-left: 12px;
          font-family: PingFangSC-Regular;
        }
      }
      .item-text {
        .status {
          display: inline-block;
          padding: 3px 10px;
          border-radius: 3px;
          font-size: 14px;
          i {
            font-size: 14px;
          }
        }
        .success {
          background: rgba(0, 201, 167, 0.1);
          color: #00c9a7;
        }
        .faild {
          background: rgba(193, 56, 56, 0.1);
          color: #c13838;
        }
      }
    }
    .area {
      height: 253px;
      display: flex;
      justify-items: left;
      align-items: flex-start;
      padding-top: 26px;
      label {
        width: 233px;
        display: flex;
        justify-items: left;
        align-items: center;
        padding-left: 32px;
        i {
          font-size: 20px;
          color: #b5d2e9;
        }
        span {
          margin-left: 12px;
          font-family: PingFangSC-Regular;
        }
      }
      .item-text {
        width: 890px;
        border: 1px solid rgba(235, 239, 241, 1);
        background: $white;
      }
      .preTxt {
        height: 200px;
        padding: 15px;
        font-family: Verdana;
        overflow-y: auto;
        vertical-align: middle;
        width: 100%;
        word-break: break-all;
      }
      code {
        line-height: 1.38;
        margin-left: -49px;
        font-family: "Verdana";
      }
      .preTxt {
        border: 1px solid #ebeff1;
        cursor: default;
        overflow-y: scroll;
        // IE下隐藏
        -ms-overflow-style: none;
        // 火狐浏览器隐藏
        scrollbar-color: transparent transparent;
      }
      .preTxt::-webkit-scrollbar {
        width: 5px;
        height: 5px;
        background: #e0e3e6;
      }
      .preTxt::-webkit-scrollbar-thumb {
        border-radius: 50px;
        background: $blue;
      }
    }
    .markdown-data {
      border-top: 1px solid #eee;
      padding: 40px;
      font-size: 14px;
    }
    .line {
      background: #f9fafc;
    }
  }
}
</style>
